<template>
  <view :style="themeColor">
    <view class="page">
      <view class="flex benben-position-layout flex flex-wrap align-center wantAlms_flex_0"
        :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
        <view class='flex flex-wrap align-center justify-between flex-sub wantAlms_fd0_0'>
          <view class='flex flex-wrap align-center wantAlms_fd0_0_c0' @tap.stop="handleJumpDiy" data-type="back"
            data-url="1">
            <text class='fu-iconfont2  wantAlms_fd0_0_c0_c0'>&#xE794;</text>
          </view>
          <view class='flex flex-wrap align-stretch justify-center'>
            <text class='wantAlms_fd0_0_c1_c0'>{{$t('随喜金额')}}</text>
          </view>
          <view class='flex flex-wrap align-center justify-end wantAlms_fd0_0_c0'>
          </view>
        </view>

      </view>
      <view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
      <!---flex布局flex布局开始-->
      <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout">
        <view class='flex flex-direction flex-wrap align-stretch wantAlms_fd1_0'>
          <text class='wantAlms_fd1_0_c0'>{{$t('功德主信息')}}</text>
          <view class='flex flex-wrap align-center justify-between wantAlms_fd1_0_c1'>
            <text class='wantAlms_fd1_0_c1_c0'>{{$t('姓名')}}</text>
            <input class='wantAlms_fd1_0_c1_c1' type="text" :placeholder="$t('请输入')" confirm-type="done" :maxlength="-1"
              v-model="name" placeholder-style="color:rgba(153, 153, 153, 1);font-size:32rpx" />
          </view>
          <view class='flex flex-wrap align-center justify-between wantAlms_fd1_0_c1' v-if=" state=='2'">
            <text class='wantAlms_fd1_0_c1_c0'>{{$t('联系方式')}}</text>
            <input class='wantAlms_fd1_0_c1_c1' type="text" :placeholder="$t('请输入')" confirm-type="done" :maxlength="20"
              placeholder-style="color:rgba(153, 153, 153, 1);font-size:32rpx" v-model="phone" />
          </view>
          <view class='flex flex-direction flex-wrap align-stretch wantAlms_fd1_0_c1' v-if=" state=='2'">
            <text class='wantAlms_fd1_0_c1_c0'>{{$t('爱心留言')}}</text>
            <view class='flex flex-wrap wantAlms_fd1_0_c3_c1'>
              <textarea class='flex wantAlms_input_fd1_0_c3_c1' :placeholder="$t('请输入~')" :maxlength="240"
                placeholder-style="color:#999;font-size:28rpx" v-model="remker" />

            </view>
          </view>
        </view>
        <view class='flex flex-wrap align-center wantAlms_fd1_1'>
        </view>
        <view class='flex flex-direction flex-wrap align-stretch wantAlms_fd1_2'>
          <text class='wantAlms_fd1_2_c0'>{{$t('布施金额')}}</text>
          <view class='flex flex-wrap align-center'>
            <benben-select-diy ref="showSelectPopup1703171562517" class-name='flex flex flex-wrap'
              :items.sync="moneyType" v-model="money" default-type="aid" default-label="name" :allow-cancel='false'
              type="radio" :disabled='false'>
              <template v-for='(item,key0) in moneyType'>
                <view v-if="item.isSelected" class='flex align-center justify-center flex wantAlms_fd1_2_c1_c0_c0'
                  :key="key0" @tap="chooseMoney(key0,item)">
                  <text class='wantAlms_fd1_2_c1_c0_c0_c0'>{{item.money}}</text>
                  <text class='wantAlms_fd1_2_c1_c0_c0_c0'>$</text>
                  <image class='wantAlms_fd1_2_c1_c0_c0_c2' mode="aspectFit" :src='STATIC_URL+"73.png"'></image>
                </view>
                <view v-else class='flex align-center justify-center flex wantAlms_fd1_2_c1_c0_c1' :key="key0"
                  @tap="chooseMoney(key0,item)">
                  <text class='wantAlms_fd1_2_c1_c0_c1_c0'>{{item.money}}</text>
                  <text class='wantAlms_fd1_2_c1_c0_c1_c0'>$</text>
                </view>
              </template></benben-select-diy>
          </view>
        </view>
        <view class='flex flex-direction flex-wrap align-stretch wantAlms_fd1_3'>
          <text class='wantAlms_fd1_3_c0'>{{$t('自定义金额')}}</text>
          <view class='flex flex-wrap align-center wantAlms_fd1_3_c1'>
            <text class='wantAlms_fd1_3_c1_c0'>$</text>
            <input class='wantAlms_fd1_3_c1_c1' type="digit" :placeholder="`0.00`" confirm-type="done" :maxlength="-1"
              placeholder-style="color:rgba(153, 153, 153, 1);font-size:32rpx" v-model="price"
              @input="customAmountFunc()" />
          </view>
        </view>
        <view class='flex flex-wrap align-center wantAlms_fd1_1'>
        </view>
      </view>

      <!---flex布局flex布局结束-->
      <!---flex布局flex布局开始-->
      <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout wantAlms_flex_2">
        <view class='flex flex-wrap align-center'>
          <text class='wantAlms_fd2_0_c0'>{{$t('请选择支付方式')}}</text>
        </view>
        <benben-select-diy ref="showSelectPopup1703169762016" class-name='flex flex-direction align-stretch flex'
          :items.sync="payType" v-model="pay_id" default-type="method_name" default-label="name" :allow-cancel='false'
          type="radio" :disabled='false'>
          <template v-for='(item,key0) in payType'>
            <view v-if="item.isSelected" class='flex justify-between flex wantAlms_fd2_1_c0' :key="key0"
              @tap="$refs.showSelectPopup1703169762016.tapHandle(key0)">
              <view class='flex flex-wrap align-center'>
                <image class='wantAlms_fd2_1_c0_c0_c0' mode="aspectFit" :src='item.thumb'></image>
                <text class='wantAlms_fd2_1_c0_c0_c1'>{{item.method_name}}</text>
              </view>
              <image class='wantAlms_fd2_1_c0_c1' mode="aspectFit" :src='STATIC_URL+"2.png"'></image>
            </view>
            <view v-else class='flex justify-between flex wantAlms_fd2_1_c0' :key="key0"
              @tap="$refs.showSelectPopup1703169762016.tapHandle(key0)">
              <view class='flex flex-wrap align-center'>
                <image class='wantAlms_fd2_1_c0_c0_c0' mode="aspectFit" :src='item.thumb'></image>
                <text class='wantAlms_fd2_1_c0_c0_c1'>{{item.method_name}}</text>
              </view>
              <image class='wantAlms_fd2_1_c0_c1' mode="aspectFit" :src='STATIC_URL+"3.png"'></image>
            </view>
          </template></benben-select-diy>
      </view>

      <!---flex布局flex布局结束-->
      <view class="flex flex-wrap align-center justify-center benben-position-layout flex wantAlms_flex_3">
        <button class='wantAlms_fd3_0' @tap.stop="payNowFunc()">{{$t('立即支付')}}</button>

      </view>
      <view :style="{height: '210rpx'}"></view>


    </view>
  </view>
</template>
<script>
  import {
    validate
  } from '@/common/utils/validate.js'
  export default {
    components: {},


    data() {
      return {
        "name": "",
        "moneyType": [],
        "money": "",
        "custom": "",
        "payType": [],
        "pay_id": "",
        "data": [],
        "phone": "",
        "remker": "",
        "order": "",
        "id": "",
        "state": "1",
        price: ''
      };
    },
    computed: {
      themeColor() {
        return this.$store.getters.themeColor
      },

    },
    watch: {},
    onLoad(options) {
      let {
        order,
        id,
        state
      } = options
      if (order !== undefined) this.order = order
      if (id !== undefined) this.id = id
      if (state !== undefined) this.state = state
      this.getMoneyFunc()
      this.getPayFunc()
    },
    onUnload() {

    },
    onReady() {

    },
    onShow() {

    },
    onHide() {

    },
    onResize() {

    },
    onPullDownRefresh() {

    },
    onReachBottom(e) {

    },
    onPageScroll(e) {

    },
    methods: {
      chooseMoney(key0, item) {
        console.log('item', this.money)
        this.$refs.showSelectPopup1703171562517.tapHandle(key0)
        this.price = item.money
      },
      //获取金额
      async getMoneyFunc() {
        //请求方法
        //数据验证

        let datamoneyType = await this.$api.get(global.apiUrls.post6560423c6509f, {

        });

        if (datamoneyType.data.code != 1) {
          this.$message.info(datamoneyType.data.msg);
          return
        }
        let infomoneyType = datamoneyType.data;
        this.moneyType = infomoneyType.data


      },
      //自定义金额
      customAmountFunc() {
        this.money = ''
        console.log('item22', this.money)
        // if (this.custom != '') {
        //   this.custom = this.money;
        // }
      },
      //获取支付
      async getPayFunc() {
        //请求方法
        //数据验证

        let datapayType = await this.$api.get(global.apiUrls.post62fc4f70a9d44, {

        });

        if (datapayType.data.code != 1) {
          this.$message.info(datapayType.data.msg);
          return
        }
        let infopayType = datapayType.data;
        this.payType = infopayType.data
        this.pay_id = this.payType[0].method_name

      },
      //立即支付
      payNowFunc() {
        if (this.state == '1') {
          if (!validate(this.name, 'require')) {
            this.$message.info(global.i18n.t('姓名不能为空'));
            return false;
          }
          if (!validate(this.price, 'require')) {
            this.$message.info(global.i18n.t('布施舍金额不能为空'));
            return false;
          }
          if (!validate(this.pay_id, 'require')) {
            this.$message.info(global.i18n.t('请选择支付方式'));
            return false;
          }
          this.$api.dbPost(global.apiUrls.post65603ff78e28e, {
            true_name: this.name,
            money: this.price,
            // remark:this.remark
            aid: this.id,
            pay_type: this.pay_id
          }).then(res => {
            if (res.data.code == 1) {
              let orderinfo = res.data.data
              this.getPay(orderinfo.order_sn)
            }
          })

        } else if (this.state == '2') {
          if (!validate(this.name, 'require')) {
            this.$message.info(global.i18n.t('姓名不能为空'));
            return false;
          }
          if (!validate(this.phone, 'require')) {
            this.$message.info(global.i18n.t('联系方式不能为空'));
            return false;
          }
          // if (!validate(this.phone, 'phone')) {
          //   this.$message.info(global.i18n.t('请输入正确的手机号'));
          //   return false;
          // }
          if (!validate(this.remker, 'require')) {
            this.$message.info(global.i18n.t('爱心留言不能为空'));
            return false;
          }
          if (!validate(this.price, 'require')) {
            this.$message.info(global.i18n.t('布施舍金额不能为空'));
            return false;
          }
          if (!validate(this.pay_id, 'require')) {
            this.$message.info(global.i18n.t('请选择支付方式'));
            return false;
          }
          this.$api.dbPost(global.apiUrls.post65619fd946f62, {
            true_name: this.name,
            money: this.price,
            remark: this.remker,
            donateinfo_id: this.id,
            mobile: this.phone,
            pay_type: this.pay_id
          }).then(res => {
            if (res.data.code == 1) {
              let orderinfo = res.data.data
              this.getPay(orderinfo.order_sn)
            }
          })
        }
      },
      getPay(order_sn) {
        uni.showLoading({
          icon: 'loading',
          title: '数据正在提交中,请勿连续点击'
        })
        this.$api.post(global.apiUrls.post659b9ab8e7217, {
          order_sn: order_sn,
          pay_type: this.pay_id
        }).then(res => {
          if (res.data.code == 1) {
            if (res.data.data.pay_type == '零元支付') {
              // 跳转支付成功
              this.$urouter.redirectTo(
                `/pages/shouye/successfulDonation/successfulDonation?oreder=${order_sn}&id=${this.id}&state=${this.state}`
              );
              uni.hideLoading()
              return;
            }
            if (res.data.data.pay_type == 'Stripe') {
              this.$urouter.navigateTo(`/pages/benben-built-in/web-view/web-view?webPath=${res.data.data.url}`);
              uni.hideLoading()
            } else {
              let datas = res.data.data
              uni.requestPayment({
                provider: 'wxpay',
                // #ifdef APP-PLUS
                orderInfo: datas,
                // #endif
                success: (e) => {
                  console.log('success', e)
                  if (e.errMsg == 'requestPayment:ok') {
                    this.$urouter.redirectTo(
                      `/pages/shouye/successfulDonation/successfulDonation?oreder=${order_sn}&id=${this.id}&state=${this.state}`
                    );
                  }
                },
                fail: (e) => {
                  console.log('e.errMsg', e)
                  // #ifdef APP-PLUS
                  let failMsg = 'requestPayment:fail canceled';
                  // #endif
                  // #ifndef APP-PLUS
                  let failMsg = 'requestPayment:fail cancel';
                  // #endif
                  if (e.errMsg == failMsg) {
                    this.$message.info(this.$t('取消支付'));
                  } else {
                    this.$message.info(this.$t("支付失败,请稍后重试1"));
                  }
                  reject(e)
                },
                complete: () => {}
              });
              uni.hideLoading()
            }

          }
        })
      },
    }
  };
</script>
<style lang="scss" scoped>
  .page {
    width: 100vw;
    overflow-x: hidden;
    min-height: calc(100vh - var(--window-bottom));
    background: rgba(247, 243, 237, 1);
    background-size: 100% auto;
  }

  .wantAlms_flex_0 {
    border-bottom: 1px solid #eee;
    background: rgba(247, 243, 237, 1);
    width: 750rpx;
    height: 88rpx;
    overflow: hidden;
    z-index: 10;
    top: 0rpx;
    background-size: 100% auto !important;
  }

  .wantAlms_fd0_0_c1_c0 {
    font-size: 36rpx;
    font-weight: 700;
    color: #333333;
    line-height: 50rpx;
  }

  .wantAlms_fd0_0_c0_c0 {
    font-size: 36rpx;
    color: #333;
  }

  .wantAlms_fd0_0_c0 {
    width: 120rpx;
  }

  .wantAlms_fd0_0 {
    padding: 0rpx 32rpx 0rpx 32rpx;
  }

  .wantAlms_fd1_3_c1_c1 {
    margin: 0rpx 0rpx 0rpx 41rpx;
  }

  .wantAlms_fd1_3_c1_c0 {
    color: #333333;
    font-size: 56rpx;
    font-weight: 400;
    line-height: 56rpx;
  }

  .wantAlms_fd1_3_c1 {
    margin: 32rpx 0rpx 0rpx 0rpx;
  }

  .wantAlms_fd1_3_c0 {
    color: #333333;
    font-size: 32rpx;
    font-weight: 400;
    line-height: 32rpx;
  }

  .wantAlms_fd1_3 {
    margin: 40rpx 32rpx 0rpx 32rpx;
  }

  .wantAlms_fd1_2_c1_c0_c1_c0 {
    color: #1A1A1A;
    font-size: 32rpx;
    font-weight: 400;
    line-height: 32rpx;
  }

  .wantAlms_fd1_2_c1_c0_c1 {
    border: 1px solid rgba(203, 203, 203, 1);
    margin: 24rpx 14rpx 0rpx 0rpx;
    width: 219rpx;
    height: 120rpx;
    border-radius: 8rpx;
    position: relative;
  }

  .wantAlms_fd1_2_c1_c0_c0_c2 {
    width: 44rpx;
    height: 44rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
    position: absolute;
    top: 0rpx;
    right: 0rpx;
  }

  .wantAlms_fd1_2_c1_c0_c0_c0 {
    color: #912F22;
    font-size: 32rpx;
    font-weight: 400;
    line-height: 32rpx;
  }

  .wantAlms_fd1_2_c1_c0_c0 {
    border: 1px solid rgba(145, 47, 34, 1);
    margin: 24rpx 14rpx 0rpx 0rpx;
    width: 219rpx;
    height: 120rpx;
    border-radius: 8rpx;
    position: relative;
  }

  .wantAlms_fd1_2_c0 {
    color: #333333;
    font-size: 32rpx;
    font-weight: 500;
    line-height: 42rpx;
  }

  .wantAlms_fd1_2 {
    margin: 32rpx 18rpx 0rpx 32rpx;
  }

  .wantAlms_fd1_1 {
    background: rgba(235, 228, 217, 1);
    margin: 32rpx 32rpx 0rpx 32rpx;
    border-radius: 10rpx;
    height: 20rpx;
    background-size: 100% auto;
  }

  .wantAlms_input_fd1_0_c3_c1 {
    width: 100%;
    height: 218rpx;
    font-size: 28rpx;
    font-weight: 400;
    color: #333;
    white-space: pre-wrap;
  }

  .wantAlms_fd1_0_c3_c1 {
    border: 1px solid rgba(232, 229, 216, 1);
    width: 661rpx;
    border-radius: 40rpx;
    padding: 24rpx;
    margin: 24rpx 0rpx 0rpx 0rpx;
  }

  .wantAlms_fd1_0_c1_c1 {
    text-align: right;
    font-size: 32rpx;
    color: #333;
  }

  .wantAlms_fd1_0_c1_c0 {
    color: #333333;
    font-size: 32rpx;
    font-weight: 400;
    line-height: 42rpx;
  }

  .wantAlms_fd1_0_c1 {
    margin: 24rpx 0rpx 0rpx 0rpx;
  }

  .wantAlms_fd1_0_c0 {
    color: #333333;
    font-size: 32rpx;
    font-weight: 500;
    line-height: 32rpx;
  }

  .wantAlms_fd1_0 {
    margin: 32rpx 32rpx 0rpx 32rpx;
  }

  .wantAlms_flex_2 {
    margin: 32rpx 0rpx 0rpx 0rpx;
    padding: 0rpx 32rpx 0rpx 32rpx;
  }

  .wantAlms_fd2_1_c0_c1 {
    width: 36rpx;
    height: 36rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
  }

  .wantAlms_fd2_1_c0_c0_c1 {
    color: #333333;
    font-size: 28rpx;
    font-weight: 400;
    line-height: 53rpx;
  }

  .wantAlms_fd2_1_c0_c0_c0 {
    width: 52rpx;
    height: 52rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
    margin: 0rpx 16rpx 0rpx 0rpx;
  }

  .wantAlms_fd2_1_c0 {
    border-bottom: 1px solid rgba(232, 229, 216, 1);
    padding: 32rpx 0rpx 32rpx 0rpx;
  }

  .wantAlms_fd2_0_c0 {
    color: #333333;
    font-size: 32rpx;
    font-weight: 500;
    line-height: 56rpx;
  }

  .wantAlms_flex_3 {
    background: rgba(247, 243, 237, 1);
    width: 750rpx;
    height: 210rpx;
    overflow: hidden;
    z-index: 10;
    bottom: calc(0rpx + var(--window-bottom));
    background-size: 100% auto;
  }

  .wantAlms_fd3_0 {
    background: rgba(145, 47, 34, 1);
    border-radius: 44rpx;
    width: 686rpx;
    line-height: 88rpx;
    font-size: 32rpx;
    color: #fff;
  }
</style>
